package com.itheima.dao;

import com.itheima.domain.Member;
import com.itheima.domain.Orders;
import com.itheima.domain.Product;
import com.itheima.domain.Traveller;
import org.apache.ibatis.annotations.*;
import org.springframework.security.core.parameters.P;

import java.util.List;

public interface OrdersDao {
    @Select("select * from orders")
    @Results({
            @Result(id = true, column = "id", property = "id"),
            @Result(column = "orderNum", property = "orderNum"),
            @Result(column = "orderTime", property = "orderTime"),
            @Result(column = "orderStatus", property = "orderStatus"),
            @Result(column = "peopleCount", property = "peopleCount"),
            @Result(column = "payType", property = "payType"),
            @Result(column = "orderDesc", property = "orderDesc"),
            @Result(column = "productId", property = "product", one = @One(select =
                    "com.itheima.dao.ProductDao.findById"))
    })
    List<Orders> findAll();

    @Select("select * from orders where id = #{ordersId}")
    @Results({
            @Result(property = "id" ,column = "id"),
    @Result(column = "productId", property = "product" , one = @One(select =
            "com.itheima.dao.ProductDao.findById")),
     @Result(column = "memberId",property = "member" , one = @One(select =
             "com.itheima.dao.MemberDao.findById")),
            @Result(column = "id" , property = "travellers", many = @Many(select =
                    "com.itheima.dao.TravellerDao.findByOrdersId"))
    })
    public Orders findById(String ordersId);
}
